{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d2aaf125",
   "metadata": {},
   "source": [
    "----------------\n",
    "* 日期：2022-10-19 \\ week09\n",
    "* 课程：python\n",
    "* 记录人：Zouyimeng\n",
    "----------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b91ee9f7",
   "metadata": {},
   "source": [
    "# 本周学习目标\n",
    "\n",
    "> 1. 列表的方法\n",
    "\n",
    "> 2. while循环"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70d5bd61",
   "metadata": {},
   "source": [
    "# 1. 列表的方法\n",
    "\n",
    "> 1. 使用.Tab查看列表的方法\n",
    "> 2. 使用help（查看方法的使用规则）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "fa781ea1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'marry', 'jan']"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"jack\",\"alex\",\"marry\",\"jan\"]\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "424b597f",
   "metadata": {},
   "source": [
    "## 1. 1列表的增加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c0f38d16",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'marry', 'jan', 'Lihua']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.append(\"Lihua\")\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "69987b8d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "0a779b70",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function insert:\n",
      "\n",
      "insert(index, object, /) method of builtins.list instance\n",
      "    Insert object before index.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.insert)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "9b772b26",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'zouyimeng', 'marry', 'jan', 'Lihua']"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.insert(2,\"zouyimeng\")\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "58b901a6",
   "metadata": {},
   "source": [
    "## 2.列表的删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "07aa9533",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "8539c0a1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'marry', 'jan', 'Lihua']"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.remove(\"zouyimeng\")\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "511327c5",
   "metadata": {},
   "source": [
    "* 正确的删除方法的流程\n",
    "> 1. 查询value是否存在列表当中\n",
    "> 2. 对存在的value进行删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "aba13ccb",
   "metadata": {},
   "outputs": [],
   "source": [
    "if \"wang\" in names:\n",
    "    names.remove(\"wang\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3fb1ff6a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践：删除系统：1.如果输入存在，删除 ；2.如果输入的结果不存在，提醒用户查询无结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "64366cb3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入要删除的内容：jack\n",
      "删除成功\n",
      "['alex', 'marry', 'jan', 'Lihua']\n"
     ]
    }
   ],
   "source": [
    "user_input_name = input(\"请输入要删除的内容：\")\n",
    "if user_input_name in names:\n",
    "    names.remove(user_input_name)\n",
    "    print(\"删除成功\")\n",
    "else:\n",
    "    print(\"您输入的结果不存在，删除无效\")\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "927b4972",
   "metadata": {},
   "source": [
    "-----------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "608c261b",
   "metadata": {},
   "source": [
    "* 列表的删除方法2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "e9f29a5c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'marry', 'jan', 'lihua']"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 重新建立names列表数据\n",
    "names = [\"jack\",\"alex\",\"marry\",\"jan\",\"lihua\"]\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "c3736a23",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "56fd120e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(index=-1, /) method of builtins.list instance\n",
      "    Remove and return item at index (default last).\n",
      "    \n",
      "    Raises IndexError if list is empty or index is out of range.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.pop)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "85cc73dd",
   "metadata": {},
   "source": [
    "### 注意:\n",
    "> 1. remove(value, /)输入某字符串，则删除特定一位\n",
    "> 2. pop(index=-1, /)\n",
    ">> 1. 若直接使用pop(),则默认删除最后一位\n",
    ">> 2. 若输入指定index(也就是字符串对应的索引值，数字0，1，2等），也可以删除指定一位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "f06ed6a2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'lihua'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "69ae652d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'marry', 'jan']"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "efcb51fb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'marry'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.pop(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "aaad3463",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'jan']"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "b5a4f73d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(names) # len是查看列表的长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "deafd88a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cd0d5dec",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "9bb564dc",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyboardInterrupt",
     "evalue": "Interrupted by user",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "Input \u001b[1;32mIn [46]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m pop_index \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mint\u001b[39m(\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m输入删除的索引值：\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m)\n",
      "File \u001b[1;32mD:\\anacondaxuexi\\lib\\site-packages\\ipykernel\\kernelbase.py:1075\u001b[0m, in \u001b[0;36mKernel.raw_input\u001b[1;34m(self, prompt)\u001b[0m\n\u001b[0;32m   1071\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_allow_stdin:\n\u001b[0;32m   1072\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m StdinNotImplementedError(\n\u001b[0;32m   1073\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mraw_input was called, but this frontend does not support input requests.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m   1074\u001b[0m     )\n\u001b[1;32m-> 1075\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_input_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m   1076\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1077\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_parent_ident\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1078\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_parent\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1079\u001b[0m \u001b[43m    \u001b[49m\u001b[43mpassword\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m   1080\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\anacondaxuexi\\lib\\site-packages\\ipykernel\\kernelbase.py:1120\u001b[0m, in \u001b[0;36mKernel._input_request\u001b[1;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[0;32m   1117\u001b[0m             \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[0;32m   1118\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m:\n\u001b[0;32m   1119\u001b[0m     \u001b[38;5;66;03m# re-raise KeyboardInterrupt, to truncate traceback\u001b[39;00m\n\u001b[1;32m-> 1120\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInterrupted by user\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28mNone\u001b[39m\n\u001b[0;32m   1121\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[0;32m   1122\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlog\u001b[38;5;241m.\u001b[39mwarning(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid Message:\u001b[39m\u001b[38;5;124m\"\u001b[39m, exc_info\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
     ]
    }
   ],
   "source": [
    "pop_index = int(input(\"输入删除的索引值：\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "7ca51339",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'pop_index' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [45]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[43mpop_index\u001b[49m \u001b[38;5;241m<\u001b[39m\u001b[38;5;28mlen\u001b[39m(names):\n\u001b[0;32m      2\u001b[0m     names\u001b[38;5;241m.\u001b[39mpop(pop_index)\n\u001b[0;32m      3\u001b[0m     \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m删除成功！\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'pop_index' is not defined"
     ]
    }
   ],
   "source": [
    "if pop_index <len(names):\n",
    "    names.pop(pop_index)\n",
    "    print(\"删除成功！\")\n",
    "else:\n",
    "    print(\"您输入的值不在index里面\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2468c59c",
   "metadata": {},
   "source": [
    "###  3.列表的修改"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "946c4990",
   "metadata": {},
   "outputs": [],
   "source": [
    "names[0] = \"zouyimeng\"\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "846e146d",
   "metadata": {},
   "source": [
    "### 4.列表的其他方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "b8a5bd9f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'marry', 'jan', 'lihua']"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"jack\",\"alex\",\"marry\",\"jan\",\"lihua\"]\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "6fecccbf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.clear()\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "0cc7f096",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'marry', 'jan', 'lihua']"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names_class1 = [\"jack\",\"alex\",\"marry\",\"jan\",\"lihua\"]\n",
    "names_class1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "946fc095",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function extend:\n",
      "\n",
      "extend(iterable, /) method of builtins.list instance\n",
      "    Extend list by appending elements from the iterable.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.extend)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "317f113c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['李晓峰', '王丽', '刘敏']"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names_class2 =[\"李晓峰\",\"王丽\",\"刘敏\"]\n",
    "names_class2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "a5ced7b7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'marry', 'jan', 'lihua', '李晓峰', '王丽', '刘敏', '李晓峰', '王丽', '刘敏']"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names_class1.extend(names_class2)\n",
    "names_class1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "614d629e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 注意：使用列表的方法的列表进行扩展"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "3c36acc5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function sort:\n",
      "\n",
      "sort(*, key=None, reverse=False) method of builtins.list instance\n",
      "    Sort the list in ascending order and return None.\n",
      "    \n",
      "    The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n",
      "    order of two equal elements is maintained).\n",
      "    \n",
      "    If a key function is given, apply it once to each list item and sort them,\n",
      "    ascending or descending, according to their function values.\n",
      "    \n",
      "    The reverse flag can be set to sort in descending order.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.sort) "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d837f126",
   "metadata": {},
   "source": [
    "---\n",
    "* sort()排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "1fe9c535",
   "metadata": {},
   "outputs": [],
   "source": [
    "立定跳远_男生 = [230,250,245,255,260,270]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "c1d0891b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[230, 245, 250, 255, 260, 270]"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "立定跳远_男生.sort()\n",
    "立定跳远_男生"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "5f5bf011",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[270, 260, 255, 250, 245, 230]"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "立定跳远_男生.sort(reverse=True)\n",
    "立定跳远_男生"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5077c415",
   "metadata": {},
   "source": [
    "## 2. while循环\n",
    "\n",
    "*while Ture 是循环概念中非常重要的一种方式。它可以实现for循环的指定次数，也可以在特定条件下停止。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "abf0331b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是风儿我是沙，缠缠绵绵到天涯.... 0\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 1\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 2\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 3\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 4\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 5\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 6\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 7\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 8\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 9\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 10\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 11\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 12\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 13\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 14\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 15\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 16\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 17\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 18\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 19\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 20\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 21\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 22\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 23\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 24\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 25\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 26\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 27\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 28\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 29\n"
     ]
    }
   ],
   "source": [
    "#它可以实现for循环的指定次数\n",
    "count = 0\n",
    "while True:\n",
    "    print(\"你是风儿我是沙，缠缠绵绵到天涯....\",count)\n",
    "    count = count + 1\n",
    "    if count ==30:\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "93442754",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 小游戏：猜数字\n",
    "# 1. hide_card : 0-100 大了， 小了\n",
    "# 2. guess_digit : 50\n",
    "import getpass\n",
    "count = 0\n",
    "hide_card = int(getpass.getpass(\"hide_card:\"))\n",
    "\n",
    "while True:\n",
    "    guess_digit = int(input(\"猜一猜（0-100）：\"))\n",
    "\n",
    "#对比：\n",
    "if hide_card == guess_digit:\n",
    "    print(\"你超棒！！！\")\n",
    "    break\n",
    "elif guess_digit>hide_card:\n",
    "    print(\"往小猜！加油！\")\n",
    "else:\n",
    "    print(\"往大的猜！\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e7bcb618",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
